﻿using System;
using System.Web.Security;
using MyWeb.Business;
using MyWeb.Data;
using MyWeb.Common;

namespace MyWeb.Modules.Products
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btSubmit_Click(object sender, EventArgs e)
        {
            ccJoin.ValidateCaptcha(TextBox1.Text);
            if (!ccJoin.UserValidated)
            {
                Label1.Text = "Mã bảo vệ chưa chính xác";
                return;
            }
            if(Check(txtPass.Text, txtRepass.Text))
            {
                var obj = new Member();
                obj.Username = txtusername.Text;
                obj.Password = EncodingDichvuwweb24h.Encode(txtPass.Text);
                obj.Name = txtname.Text;
                obj.Birthday = DateTimeClass.ConvertDateTime(txtBirthday.Text, "MM/dd/yyyy HH:mm:ss");
                obj.Email = txtEmail.Text;
                obj.Phone = txtphone.Text;
                obj.Company = txtCompany.Text;
                obj.Taxcode = txtTaxCode.Text;
                obj.WebsiteCompany = txtWebsite.Text;
                obj.PhoneCompany = txtphoneCompany.Text;
                obj.Fax = txtfax.Text;
                obj.DirectorName = txtDirectorPhone.Text;
                obj.DirectorPhone = txtDirectorPhone.Text;
                if(MemberService.Member_Insert(obj))
                {
                    FormsAuthentication.SetAuthCookie(txtusername.Text, false);
                    Session["FullName"] = txtname.Text;
                    Session["UserName"] = txtusername.Text.Trim();
                    var sql = new SqlDataProvider();
                    var memberid = sql.MaxId("Member", "Id");
                    Session["MemberId"] = memberid;
                    ControlClass.ResetControlValues(this);
                    Response.Redirect("gio-hang.html");
                }
            }
        }
        #region check
        private bool Check(string s1, string s2)
        {
            return s1.Equals(s2);
        }
        #endregion
    }
}